package com.zoshine.zzg.pojo.pojostatus;

import com.zoshine.zzg.base.Status;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * 缺货状态
 *
 * @author 贾俊峰
 * @time 2017/7/7 21:56
 */
public enum GoodsReturnStatus {
    REPLENISHMENT(1, "待导出外网"),
    PART_FINISH(2, "已导出外网"),
    PENDING_BACK_GOODS(3, "待补货"),
    FINISH_BACK_GOODS(4, "待导入内网"),
    SURE_GOODS_RETURN(5, "已导入内网"),
    PENDING_GOODS_RETURN(6, "待收货"),
    FINISH_GOODS_RETURN(9, "已收货"),
    ;
    private int value;
    private String desc;

    GoodsReturnStatus(final int value, final String desc) {
        this.value = value;
        this.desc = desc;
    }

    public int getValue() {
        return value;
    }

    public static String getDesc(Integer value) {
        for (GoodsReturnStatus commonStatus : GoodsReturnStatus.values()) {
            if (Objects.equals(value, commonStatus.value)) {
                return commonStatus.desc;
            }
        }
        return null;
    }

    // 缓存一个列表，防止每次使用都进行循环
    private static List<Status> statusList;
    public static List<Status> getList() {
        if (statusList == null || statusList.size() == 0) {
            statusList = new ArrayList<>();
            for (GoodsReturnStatus commonStatus : GoodsReturnStatus.values()) {
                // 将状态存入列表
                Status status = new Status();
                status.setValue(commonStatus.value);
                status.setDesc(commonStatus.desc);
                statusList.add(status);
            }
        }
        return statusList;
    }
}
